/*============================================================================*/
/*                   CONTINENTAL AUTOMOTIVE SYSTEMS                           */
/*============================================================================*/
/*                        OBJECT SPECIFICATION                                */
/*============================================================================*
* name:            MAL_Timer.c
* version:         1.0
* created_by:      Continental
* date_created:    June 7 2013
*=============================================================================*/
/* DESCRIPTION : Source file for abstraction layer for LED                    */
/*============================================================================*/
/* FUNCTION COMMENT : Source file abstraction layer for LED                   */
/*                                                                            */
/*============================================================================*/
/*                               OBJECT HISTORY                               */
/*============================================================================*/
/*  REVISION |   DATE      |                               |      AUTHOR      */
/*----------------------------------------------------------------------------*/
/*  1.0      | 07/jun/2013 |                               | Continental      */
/* Initial version for the Lab 2 using Freescale Bolero micro.                */
/*----------------------------------------------------------------------------*/
/*  2.0      | 22/jun/2013 |                               | Eunice Ibarra    */
/* Modified to use naming conventions						                  */
/*============================================================================*/

#include "sysinit.h"
#include "MAL_Timer.h"


/****************************************************************************************************/
/**
* \brief    Initialize STM timer
* \author   Victor Ruiz/ Eunice Ibarra
* \param    void 
* \return   void
*/
void MAL_Timer_Init(void)
{
	STM.CR.B.CPS=0xFF; //SYSTEM CLK DIVIDEB BY 256, BASE TIME FOR COUNTER=4uS.
	STM.CR.B.FRZ=0x01; //FREEZE ENABLED TO ALLOW COUNTER TO BE STOPPED IN DEBUG MODE
	STM.CR.B.TEN=0x01; //TIMER COUNTER ENABLED 
	
}

/****************************************************************************************************/
/**
* \brief    Configures individual STM timer chanel
* \author   Victor Ruiz / Eunice Ibarra
* \param    T_UBYTE channel - GPIO channel to be configured
* \param    T_ULONG time - time in ms for timer
* \return   void
*/
void MAL_Timer10ms_Init_channel(void)
{
	STM.CH[0].CCR.B.CEN=1; 		//CHANNEL O ENABLED
	STM.CH[0].CIR.B.CIF=1; 		// 1 TO CLEAR THE FIELD 
	STM.CH[0].CMP.R=TIME_10MS+STM.CNT.R;   
}

/****************************************************************************************************/
/**
* \brief    Configures individual STM timer chanel
* \author   Victor Ruiz / Eunice Ibarra
* \param    T_UBYTE channel - GPIO channel to be configured
* \param    T_ULONG time - time in ms for timer
* \return   void
*/
void MAL_Timer400ms_Init_channel(void)
{
	STM.CH[1].CCR.B.CEN=1; 		//CHANNEL O ENABLED
	STM.CH[1].CIR.B.CIF=1; 		// 1 TO CLEAR THE FIELD 
	STM.CH[1].CMP.R=TIME_400MS+STM.CNT.R;   
}

/****************************************************************************************************/
/**
* \brief    Configures individual STM timer chanel
* \author   Victor Ruiz / Eunice Ibarra
* \param    T_UBYTE channel - GPIO channel to be configured
* \param    T_ULONG time - time in ms for timer
* \return   void
*/
void MAL_Timer500ms_Init_channel(void)
{
	STM.CH[2].CCR.B.CEN=1; 		//CHANNEL O ENABLED
	STM.CH[2].CIR.B.CIF=1; 		// 1 TO CLEAR THE FIELD 
	STM.CH[2].CMP.R=TIME_500MS+STM.CNT.R;   
}

/****************************************************************************************************/
/**
* \brief    Configures individual STM timer chanel
* \author   Victor Ruiz / Eunice Ibarra
* \param    T_UBYTE channel - GPIO channel to be configured
* \param    T_ULONG time - time in ms for timer
* \return   void
*/
void MAL_Timer5s_Init_channel(void)
{
	STM.CH[3].CCR.B.CEN=1; 		//CHANNEL O ENABLED
	STM.CH[3].CIR.B.CIF=1; 		// 1 TO CLEAR THE FIELD 
	STM.CH[3].CMP.R=TIME_5S+STM.CNT.R;   
}

/****************************************************************************************************/
/**
* \brief    Reads flag of an individual STM timer chanel
* \author   Victor Ruiz / Eunice Ibarra
* \param    T_UBYTE channel - GPIO channel to be configured
* \param    T_ULONG time - time in ms for timer
* \return   void
*/
T_ULONG MAL_Read10msFLAG (void)
{
	return STM.CH[0].CIR.R; 
}


/****************************************************************************************************/
/**
* \brief    Reads flag of an individual STM timer chanel
* \author   Victor Ruiz / Eunice Ibarra
* \param    T_UBYTE channel - GPIO channel to be configured
* \param    T_ULONG time - time in ms for timer
* \return   void
*/
T_ULONG MAL_Read400msFLAG (void)
{
	return STM.CH[1].CIR.R; 
}


/****************************************************************************************************/
/**
* \brief    Reads flag of an individual STM timer chanel
* \author   Victor Ruiz / Eunice Ibarra
* \param    T_UBYTE channel - GPIO channel to be configured
* \param    T_ULONG time - time in ms for timer
* \return   void
*/
T_ULONG MAL_Read500msFLAG (void)
{
	return STM.CH[2].CIR.R; 
}


/****************************************************************************************************/
/**
* \brief    Reads flag of an individual STM timer chanel
* \author   Victor Ruiz / Eunice Ibarra
* \param    T_UBYTE channel - GPIO channel to be configured
* \param    T_ULONG time - time in ms for timer
* \return   void
*/
T_ULONG MAL_Read5sFLAG (void)
{
	return STM.CH[3].CIR.R; 
}


/****************************************************************************************************/


		